<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Alsdk/DescribeUserDomains')}">域名列表</a></li>
        <li class="active"><a href="{:url('Alsdk/AddLiveDomain')}">添加域名</a></li>
    </ul>
    <form action="{:url('Alsdk/AddLiveDomain')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
		<div class="form-group">
			<label class="col-sm-2 control-label"><span class="form-required">*</span>直播域名:</label>
			<div class="col-md-6 col-sm-10">
				<input class="form-control" type="text" name="DomainName" required value="" placeholder="请输入直播域名"/>
                <p class="help-block">需要接入直播的域名。支持泛域名，以符号“.”开头，如：.a.com</p>
			</div>
		</div>
    	<div class="form-group">
			<label class="col-sm-2 control-label"><span class="form-required">*</span>域名业务类型:</label>
			<div class="col-md-6 col-sm-10">
				<select id="LiveDomainType" name="LiveDomainType" class="form-control">
					<option value="liveVideo" >播流域名</option>
					<option value="liveEdge" >边缘推流域名</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label"><span class="form-required">*</span>直播域名单元化信息:</label>
			<div class="col-md-6 col-sm-10">
				<select id="Region" name="Region" class="form-control">
					<option value="cn-beijing" >cn-beijing</option>
					<option value="cn-shanghai" >cn-shanghai</option>
					<option value="ap-southeast-1" >ap-southeast-1</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label"><span class="form-required">*</span>加速区域:</label>
			<div class="col-md-6 col-sm-10">
				<select id="Scope" name="Scope" class="form-control">
					<option value="domestic" >国内</option>
					<option value="overseas" >海外</option>
					<option value="global" >全球</option>
				</select>
			</div>
		</div>
        <div class="col-sm-offset-2 col-sm-10">
			<button type="button" class="btn btn-primary" id="js-ajax-submit">{:lang("SAVE")}</button>
			<a class="btn btn-default" href="{:url('Alsdk/DescribeUserDomains')}">返回</a>
		</div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
	$('#js-ajax-submit').on('click', function () {
		var data = {
			DomainName:$("input[name='DomainName']").val(),
			LiveDomainType:$("#LiveDomainType option:selected").val(),
			Region:$("#Region option:selected").val(),
			Scope:$("#Scope option:selected").val(),
		}
		var reg = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/;
		if ( data.DomainName == '' || data.DomainName == null ) {
			tishi('直播域名不能为空')
			return false
		} else if ( !reg.test(data.DomainName) ) {
			tishi('直播域名不合法')
			return false
		}
        $.ajax({
	        url: "{:url('Alsdk/AddLiveDomain')}",
	        dataType: 'json',
	        data: data,
	        type: "POST",
	        success: function(data){
				if (data.code == '1') {
	                noty({
	                    text: data.msg,
	                    type: 'success',
	                    layout: 'topCenter',
	                    modal: true,
	                    timeout: 800,
	                    callback: {
	                        afterClose: function () {
                                if (data.url) {
                                    //返回带跳转地址
                                    window.location.href = data.url;
                                } else {
                                    //刷新当前页
                                    reloadPage(window);
                                }
	                        }
	                    }
	                }).show();
	            } else if (data.code == '0') {
	                art.dialog({
	                    content: data.msg,
	                    icon: 'warning',
	                    ok: function () {
	                        this.title(data.msg);
	                        return true;
	                    }
	                });
	            }
	        }
        });
    });

	// 信息提示
    function tishi(msg){
    	art.dialog({
            id: 'warning',
            icon: 'warning',
            title: '提示',
            content: msg,
            cancelVal: '关闭',
            ok: function () {
              
            }
        });
    }
</script>
</body>
</html>
